package com.th.apicenter.mi;

import com.th.apicenter.mi.entity.ThMiData;
import com.th.apicenter.mi.service.MiService;
import com.th.apicenter.tools.ThResult;
import com.th.apicenter.tools.ThTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/mi/api")
public class MiController {

    @Autowired
    private MiService miService;

    /**
     * https://apibiz.tinghongzz.com/mi/api/monitor?response_validate=false&imei=__IMEI__&oaid=__OAID__&click_time=__TS__&callback_url=__CALLBACK__&app_id=__APPID__&adid=__ADID__&campaign_id=__CAMPAIGNID__&customer_id=__CUSTOMERID__&sign=__SIGN__
     */
    @GetMapping("/monitor")
    public ThResult receiveUrl(@RequestParam(name = "response_validate", required = false) String response_validate,
                                @RequestParam(name = "imei", required = false) String imei,
                                @RequestParam(name = "oaid", required = false) String oaid,
                                @RequestParam(name = "click_time", required = false) String click_time,
                                @RequestParam(name = "callback_url", required = false) String callback_url,
                                @RequestParam(name = "app_id", required = false) String app_id,
                                @RequestParam(name = "adid", required = false) String adid,
                                @RequestParam(name = "campaign_id", required = false) String campaign_id,
                                @RequestParam(name = "customer_id", required = false) String customer_id,
                                @RequestParam(name = "sign", required = false) String sign) {
        ThMiData thMiData = new ThMiData();
        thMiData.setAccountId(ThTools.isNull(customer_id) ? "" : customer_id);
        thMiData.setImei(ThTools.isNull(imei) ? "" : imei);
        thMiData.setOaid(ThTools.isNull(oaid) ? "" : oaid);
        thMiData.setClickTime(ThTools.isNull(click_time) ? "" : click_time);
        thMiData.setCallbackUrl(ThTools.isNull(callback_url) ? "" : callback_url);
        thMiData.setAppId(ThTools.isNull(app_id) ? "" : app_id);
        thMiData.setAdid(ThTools.isNull(adid) ? "" : adid);
        thMiData.setCampaignId(ThTools.isNull(campaign_id) ? "" : campaign_id);
        thMiData.setCustomerId(ThTools.isNull(customer_id) ? "" : customer_id);
        thMiData.setSign(ThTools.isNull(sign) ? "" : sign);
        String receive = miService.receive(thMiData);
        return ThResult.success(receive);
    }

}
